package hotel.action;

import hotel.service.RequestService;
import hotel.service.ServiceManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
 * This class Delete Request from DataBase
 * @author Alex
 *
 */
public class DeleteRequestAction extends Action 
{
	private static final Logger logger = Logger.getLogger(DeleteRequestAction.class);
	private static final String DELETEREQUESTACTION_ERROR = "Error in DeleteRequestAction:";
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
		    throws Exception 
		    {
			String mapper = ForwardActionTo.ERROR;
			int id;
			try
			{
				RequestService requestService = ServiceManager.getDefault().getRequestService();
				id = Integer.valueOf(request.getParameter("id"));
				requestService.changeStatus(id, "deleted");
				mapper = ForwardActionTo.SUCCESS;
			}
			catch(NullPointerException e)
			{
				logger.error(DELETEREQUESTACTION_ERROR + e);
		 	}

				return mapping.findForward(mapper);
		    }
}
